OBJ = obj
CC = clang++
WARN_FLAGS = -Wall                              \
             -Wextra                            \
             -pedantic                          \
             -Wformat=2                         \
             -Wmissing-include-dirs             \
             -Wswitch-default                   \
             -Wswitch-enum                      \
             -Wunused                           \
             -Wundef                            \
             -Wshadow                           \
             -Wpointer-arith                    \
             -Wcast-qual                        \
             -Wcast-align                       \
             -Wwrite-strings                    \
             -Wconversion                       \
             -Wsign-compare                     \
             -Waddress                          \
             -Wmissing-field-initializers       \
             -Wredundant-decls                  \
             -Winline                           \
             -Wdisabled-optimization            \
             -Woverlength-strings

OPTIMIZE_FLAGS = -fstrict-aliasing

HARDWARE_FLAGS = -mtune=native

CPPFLAGS = $(HARDWARE_FLAGS)                    \
           $(OPTIMIZE_FLAGS)                    \
           -g                                   \
           -ffor-scope                          \
           -fno-gnu-keywords                    \
           -fno-operator-names                  \
           -Wabi                                \
           -Wctor-dtor-privacy                  \
           -Wnon-virtual-dtor                   \
           -Wreorder                            \
           -Weffc++                             \
           -Wold-style-cast                     \
           -Woverloaded-virtual                 \
           -Wsign-promo                         \
           -std=c++11                           \
           -stdlib=libc++                       \
           -Wsign-promo                         \
           $(WARN_FLAGS)

CPPINCLUDES = -I.
LDFLAGS = -stdlib=libc++
CPPLIBS =

ARFLAGS = -r                                    \
          -c                                    \
          -s

HEADERS = 

.SECONDEXPANSION:
all: .create_obj_dir $$(TARGET)

.PHONY: .create_obj_dir
.create_obj_dir:
	test -d $(OBJ) || mkdir $(OBJ)

# pattern rules
# object files
$(OBJ)/%.o: %.cc $(HEADERS)
	$(CC) $(CPPFLAGS) $(USER_INCLUDES) $(CPPINCLUDES) $(POST_INCLUDES) -c $< -o $@

# task files
%.tsk: $(CPPOBJS)
	$(CC) $(LDFLAGS) $(USER_LIBS) $(CPPOBJS) $(CPPLIBS) $(POST_LIBS) -o $@

# archive files
%.a:
	$(AR) $(ARFLAGS) $@ $(CPPOBJS) 

.PHONY: clean
clean:
	-rm -rf $(OBJ) $(TARGET)
